/*
 * ResourceExtractorAspect.cpp
 *
 *  Created on: Nov 16, 2008
 *      Author: Ryan
 */

#include "ResourceExtractorAspect.h"

namespace OOInterface
{

ResourceExtractorAspect::ResourceExtractorAspect()
{
}

ResourceExtractorAspect::~ResourceExtractorAspect()
{
}

float ResourceExtractorAspect::getAmountGenerated( const Resource& r, const GameMap& map, const Point3f& loc ) const
{
	float amount = 0.0f;
	if( r == *_resource )
	{

		int startX = (unsigned int) (-1 * _radius + loc.getX());
		if( startX < 0 ) startX = 0;

		int startY = (unsigned int) (-1 * _radius + loc.getZ());
		if( startY < 0 ) startY = 0;

		Point3f point;

		unsigned int maxX = int(_radius + loc.getX());
		if( maxX > map.getWidth()) maxX = map.getWidth();

		unsigned int maxY = int(_radius + loc.getZ());
		if( maxY > map.getWidth()) maxY = map.getHeight();

		for( unsigned int x = startX; x <= maxX; ++x )
		{
			for( unsigned int y = startY; y <= maxY; ++y )
			{
				point.setX(x); point.setZ(y);

				if( loc.distanceTo(point) < _radius )
					amount += map.getResourceDensity( r, x, y );
			}
		}
	}

	return amount;
}

}
